package com.example.simplenet;

import java.util.ArrayList;

import com.example.simplenet.ConnectionMan.Mission;
import com.example.simplenet.ConnectionMan.MissionType;

import android.util.SparseArray;

public class ArmyController {

	private static boolean mRunAway = false;
	private static boolean mAttackAbandoned = false;
	private static boolean mUnderAttack = false;
	private static ArrayList<Mission> mMyMissions = new ArrayList<ConnectionMan.Mission>();
	private static ArrayList<Mission> mEnemyMissions = new ArrayList<ConnectionMan.Mission>();
	private static ArrayList<Mission> mResMissions = new ArrayList<ConnectionMan.Mission>();
	private static ArrayList<Mission> mAllianceMissions = new ArrayList<ConnectionMan.Mission>();
	private static ArrayList<Mission> mMoveMissions = new ArrayList<ConnectionMan.Mission>();
	
	private static SparseArray<String> mProvincesInfo = null;

	public static boolean isRunAway() {
		return mRunAway;
	}
	
	public static void setRunAway(boolean runAway) {
		mRunAway = runAway;
	}

	public static boolean isAttackAbandoned() {
		return mAttackAbandoned;
	}
	
	public static boolean setAttackAbandoned(boolean attack) {
		if (mAttackAbandoned != attack) {
			mAttackAbandoned = attack;
			return true;
		}
		return false;
	}

	public static boolean isUnderAttack() {
		return mUnderAttack;
	}
	
	public static void setIsUnderAttack(boolean attack) {
		mUnderAttack = attack;
	}
	
	public static SparseArray<String> getProvincesInfo() {
		return mProvincesInfo;
	}

	public static void setProvincesInfo(SparseArray<String> provincesInfo) {
		mProvincesInfo = provincesInfo;
	}

	public static ArrayList<Mission> getAllMissions() {
		ArrayList<Mission> all = new ArrayList<ConnectionMan.Mission>();
		all.addAll(mAllianceMissions);
		all.addAll(mEnemyMissions);
		all.addAll(mMoveMissions);
		all.addAll(mMyMissions);
		all.addAll(mResMissions);
		return all;
	}
	
	public static ArrayList<Mission> getMyMissions() {
		return mMyMissions;
	}
	
	public static void setMissions(ArrayList<Mission> missions) {
		mMyMissions.clear();
		mEnemyMissions.clear();
		mMoveMissions.clear();
		mAllianceMissions.clear();
		mResMissions.clear();
		for (Mission mission : missions) {
			if (mission.getType() == MissionType.MY) {
				mMyMissions.add(mission);
			} else if (mission.getType() == MissionType.ENEMY) {
				mEnemyMissions.add(mission);
			} else if (mission.getType() == MissionType.MOVE) {
				mMoveMissions.add(mission);
			} else if (mission.getType() == MissionType.ALLIANCE) {
				mAllianceMissions.add(mission);
			} else if (mission.getType() == MissionType.RESOURCES) {
				mResMissions.add(mission);
			}
		}
	}
}
